#include <iostream>
#include <time.h>
#include <windows.h>
#include<set>
using namespace std;

int t,n,m,k,ma;
int currentCase = 1;
int color[26];
int point[25];
int match = 0;
set<int>visit;

bool check(int color, int i){
	if (i - 1 >= 0 && point[i - 1] == color)return false;
	if (i - n >= 0 && point[i - n] == color)return false;
	return true;
}

void display(){
	printf( "Case #%d:\nYES\n" ,currentCase);
	for (int j = 0; j < n; j++){
		for (int i = 0; i < m; i++){
			printf( "%d",point[i*n + j]);
		}
		printf("\n");
	}
}


void draw(int start, int currentColor,int a){
	int b = 0;
	if (start - n >= 0)b = point[start - n];
	for (int j = 1; j < k; j++){
		if (currentColor != a&&currentColor != b&&color[currentColor]>0 && color[currentColor] <= (ma - start)){
			point[start] = currentColor;
			color[currentColor]--;
			int nextColor;
			if (currentColor == k)nextColor = 1;
			else nextColor = currentColor + 1;
			if (start < m*n - 1){
				draw(start + 1, nextColor,currentColor);
			}
			else {
				display();
				match = 1;
				return;
			}
			if (match == 1)return;
			point[start] = 0;
			color[currentColor]++;
		}
		if (currentColor == k)currentColor = 1;
		else currentColor++;
	}
}


int main(){
	scanf_s("%d", &t);
	while (t--){
		scanf_s("%d%d%d", &n, &m, &k);
		for (int j = 1; j <=k; j++){
			scanf_s("%d", color+j);
		}
		match = 0;
		ma = m*n;
		LARGE_INTEGER  num;
		LONGLONG start, end, freq;
		QueryPerformanceFrequency(&num);
		freq = num.QuadPart;
		QueryPerformanceCounter(&num);
		start = num.QuadPart;
		draw(0, 1,0);
		if (match == 0){
			printf("Case #%d:\n", currentCase);
			printf("NO\n");
		}
		currentCase++;
		QueryPerformanceCounter(&num);
		end = num.QuadPart;
		printf("time=%d\n", end - start);
		system("PAUSE");
	}
	return 0;
}